package com.company.workflow.controller;

import com.company.oa.common.api.Result;
import com.company.workflow.model.vo.ProcessInstanceVO;
import com.company.workflow.model.vo.ProcessStatisticsVO;
import com.company.workflow.service.ProcessMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/process/monitor")
public class ProcessMonitorController {

    @Autowired
    private ProcessMonitorService processMonitorService;

    @GetMapping("/instances")
    public Result<List<ProcessInstanceVO>> listInstances(
            @RequestParam(required = false) String processDefinitionKey,
            @RequestParam(required = false) String status) {
        return Result.success(processMonitorService.listInstances(processDefinitionKey, status));
    }

    @GetMapping("/statistics")
    public Result<ProcessStatisticsVO> getStatistics() {
        return Result.success(processMonitorService.getStatistics());
    }

    @GetMapping("/trend")
    public Result<Map<String, Object>> getTrend(
            @RequestParam(required = false) String timeRange) {
        return Result.success(processMonitorService.getTrend(timeRange));
    }

    @PostMapping("/instance/{processInstanceId}/suspend")
    public Result<Boolean> suspendInstance(@PathVariable String processInstanceId) {
        processMonitorService.suspendInstance(processInstanceId);
        return Result.success(true);
    }

    @PostMapping("/instance/{processInstanceId}/activate")
    public Result<Boolean> activateInstance(@PathVariable String processInstanceId) {
        processMonitorService.activateInstance(processInstanceId);
        return Result.success(true);
    }
} 